package com.gmall.coupon.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_PaySuccess {

    public static final String Exchange_Fanout_PaySuccess = "Exchange_Fanout_PaySuccess";

    public static final String Queue_PaySuccess_Order = "Queue_PaySuccess_Order";
    public static final String Queue_PaySuccess_Coupon = "Queue_PaySuccess_Coupon";


    @Bean(Exchange_Fanout_PaySuccess)
    public Exchange exchange_Fanout_PaySuccess(){
        return ExchangeBuilder.fanoutExchange(Exchange_Fanout_PaySuccess).build();
    }

    @Bean(Queue_PaySuccess_Order)
    public Queue queue_PaySuccess_Order(){
        return QueueBuilder.durable(Queue_PaySuccess_Order).build();
    }

    @Bean(Queue_PaySuccess_Coupon)
    public Queue queue_PaySuccess_Coupon(){
        return QueueBuilder.durable(Queue_PaySuccess_Coupon).build();
    }

    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_fanout_Order(
            @Qualifier(Queue_PaySuccess_Order) Queue queue,
            @Qualifier(Exchange_Fanout_PaySuccess) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    @Bean
    public Binding binding_fanout_Coupon(
            @Qualifier(Queue_PaySuccess_Coupon) Queue queue,
            @Qualifier(Exchange_Fanout_PaySuccess) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
